﻿import pyautogui
import time
import os
import json
import pyperclip

def load_pos_info():
    file_path = os.path.join(os.path.dirname(__file__), "location.json")
    with open(file_path, 'r', encoding='utf-8') as file:
        return json.load(file)

def get_zenik_value():
    pos_info = load_pos_info()
    averaged = pos_info["averaged"]
    measscreen = pos_info["measscreen"]
    sheet = pos_info["sheet"]
    comax = pos_info["comax"]
    comay = pos_info["comay"]
    livevideo = pos_info["livevideo"]
    freeze = pos_info["freeze"]   

    # averaged
    pyautogui.moveTo(averaged)
    pyautogui.click(clicks=1)
    # sleep(5)
    time.sleep(5)
    # sheet
    pyautogui.moveTo(sheet)
    pyautogui.click(clicks=1)
    # sleep(1)
    time.sleep(1)
    # comax
    pyautogui.moveTo(comax)
    pyautogui.click(clicks=2)
    pyautogui.hotkey("ctrl", "c")
    time.sleep(1)
    comax_value = pyperclip.paste()
    # comay
    pyautogui.moveTo(comay)
    pyautogui.click(clicks=2)
    pyautogui.hotkey("ctrl", "c")
    time.sleep(1)
    comay_value = pyperclip.paste()
    # measscreen
    pyautogui.moveTo(measscreen)
    pyautogui.click(clicks=1)
    time.sleep(1)
    # livevideo
    pyautogui.moveTo(livevideo)
    pyautogui.click(clicks=1)
    time.sleep(1)
    return {"comax_value": comax_value, "comay_value": comay_value}
    
def test():
    pos_info = load_pos_info()
    guanxi = pos_info["guanxi"]
    pyautogui.moveTo(guanxi)
    pyautogui.click(clicks=1)
    time.sleep(1)
    pyautogui.click(clicks=1)
    time.sleep(1)
    pyautogui.hotkey("ctrl", "c")
    time.sleep(0.5)
    # print("value =", pyperclip.paste())
    return {"value": pyperclip.paste()}

if __name__ == "__main__":
    time.sleep(5)
    test()
    
